package hai.com.android_test.base;

import android.app.Application;

import com.franmontiel.persistentcookiejar.ClearableCookieJar;
import com.franmontiel.persistentcookiejar.PersistentCookieJar;
import com.franmontiel.persistentcookiejar.cache.SetCookieCache;
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor;

import java.util.concurrent.TimeUnit;

import hai.com.android_test.mixed.LoggingIntercepror;
import hai.com.android_test.utils.Helper;
import hai.com.android_test.utils.HttpUtils;
import okhttp3.OkHttpClient;

/**
 * Created by 黄海 on 11/27/2016.
 */

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        HttpUtils.init(this);
        Helper.init(getApplicationContext());
        initOkHttpClient();

    }

    private void initOkHttpClient() {
        ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getApplicationContext()));
        OkHttpClient okHttpClient = new OkHttpClient.Builder().cookieJar(cookieJar).connectTimeout(5000, TimeUnit.MILLISECONDS)
                .readTimeout(5000, TimeUnit.MILLISECONDS).addInterceptor(new LoggingIntercepror()).build();
        Helper.initHttpClient(okHttpClient);
    }
}
